home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / Algorithms / quick.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-19  |  2.1 KB  |  74 lines

  1. #include<hold/anim.h>
  2.  
  3. /* 000 */ void quicksort(int [], int,int);
  4.  
  5. /* 001 */ void quick_control(){
  6. /* 002 */ int d[10] = {-1,4,2,7,6,3,0,1,8,5};
  7. /* 003 */ int parts = 10;
  8.  
  9.             a_func("quick_control",1);
  10.             a_irayini(d,"d",parts,2);
  11.             a_intini(parts,"parts",3);
  12.             a_show(4);
  13. /* 004 */   quicksort(d,0,parts-1);
  14.             a_endfunc("quick_control",5);
  15. /* 005 */ }
  16.  
  17. /* 006 */ void quicksort(int a[],int l,int r ){
  18. /* 007 */ int v,i,j,t;
  19.  
  20.             a_func("quicksort",6);
  21.             a_iraypas("a",6);
  22.             a_intini(l,"l",6);
  23.             a_intini(r,"r",6);
  24.             a_intini(v,"v",7);
  25.             a_intini(i,"i",7);
  26.             a_intini(j,"j",7);
  27.             a_intini(t,"t",7);
  28.             a_intcomp("r>l",8);
  29. /* 008 */   if(r>l){
  30. /* 009 */      v=a[r];
  31.                a_intass("v","a[r]",9);
  32. /* 010 */      i=l-1;
  33.                a_intass("i","l-1",10);
  34. /* 011 */      j=r;
  35.                a_intass("j","r",11);
  36.                a_show(12);
  37. /* 012 */      for(;;){
  38.                  a_intass("i","i+1",13);
  39.                  a_intcomp("a[i]<v",13);
  40. /* 013 */        while(a[++i] < v){
  41.                    a_intass("i","i+1",13);
  42.                    a_intcomp("a[i]<v",13);
  43. /* 014 */        }
  44.                  a_intass("j","j-1",15);
  45.                  a_intcomp("a[j]>v",15);
  46. /* 015 */        while(a[--j] > v){
  47.                    a_intass("j","j-1",15);
  48.                    a_intcomp("a[j]>v",15);
  49. /* 016 */        }
  50.                  a_intcomp("i>=j",17);
  51. /* 017 */        if(i >= j) break;
  52. /* 018 */        t = a[i];
  53.                  a_intass("t","a[i]",18);
  54. /* 019 */        a[i] = a[j];
  55.                  a_intass("a[i]","a[j]",19);
  56. /* 020 */        a[j] = t;
  57.                  a_intass("a[j]","t",20);
  58.                  a_show(12);
  59. /* 021 */      }
  60. /* 022 */      t = a[i];
  61.                a_intass("t","a[i]",22);
  62. /* 023 */      a[i] = a[r];
  63.                a_intass("a[i]","a[r]",23);
  64. /* 024 */      a[r] = t;
  65.                a_intass("a[r]","t",24);
  66.                a_show(25);
  67. /* 025 */      quicksort(a, l, i-1);
  68.                a_show(26);
  69. /* 026 */      quicksort(a, i+1,r);
  70. /* 027 */   }
  71.             a_endfunc("quicksort",28);
  72. /* 028 */ }
  73.  
  74.